<template>
  <el-dropdown trigger="click" @command="changeLanguage">
    <div>
      <svg-icon style="color: #fff; font-size: 20px" icon-class="language" />
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh" :disabled="'zh' === $i18n.locale">
        韩文
      </el-dropdown-item>
      <el-dropdown-item command="en" :disabled="'en' === $i18n.locale">
        英文
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script>
import cookie from 'js-cookie'
export default {
  name: 'Lang',
  methods: {
    changeLanguage (command) {
      // 动态切换多语言 => 点击可以获取对应菜单项上绑定的 command="en"值
      this.$i18n.locale = command // 设置给本地的i18n插件
      // 本地持久化存储当前语言标识 => 默认存的是session形式,关闭浏览器这个数据会删除
      // 语法: cookie.set(key, value, {expires: day/date对象})
      cookie.set('hr-lang', command)
      this.$message.success(`切换${command}语言成功`)
    }
  }
}
</script>
